﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Happy.StateManager;
using Happy.Examples.ManufactureManagement.Domain.Bases;
using Happy.Examples.ManufactureManagement.Domain.QualityTests;

namespace Happy.Examples.ManufactureManagement.Domain.Test.QualityTests
{
    [TestClass]
    public class QualityTestTest
    {
        [TestMethod]
        public void TestUnSavedQualityTest()
        {
            var entity = this.MockUnQualityTest(Status.UnSaved);
            entity.AddItem(new QualityTestItem(Guid.NewGuid(), entity.Id));
            entity.Save();

            Assert.AreEqual(Status.Saved, entity.Status);
        }

        [TestMethod]
        public void TestSavedQualityTest()
        {
            var entity = this.MockUnQualityTest(Status.Saved);
            entity.AddItem(new QualityTestItem(Guid.NewGuid(), entity.Id));
            entity.Submit();

            Assert.AreEqual(Status.Submitted, entity.Status);
        }

        [TestMethod]
        [ExpectedException(typeof(StateScheduleException))]
        public void TestSubmittedQualityTest()
        {
            var entity = this.MockUnQualityTest(Status.Submitted);
            entity.AddItem(new QualityTestItem(Guid.NewGuid(), entity.Id));
        }

        private QualityTest MockUnQualityTest(Status status)
        {
            return new QualityTest
                {
                    Id = Guid.NewGuid(),
                    Status = status
                };
        }
    }
}
